package Demo1;

class Teacher implements Cloneable{
    public String name = "MrLi";

    @Override
    public String toString() {
        return "Teacher{" +
                "name='" + name + '\'' +
                '}';
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}
public class Student implements Cloneable{
    public String name;
    public int age;
    public Double score;
    public Teacher teacher = new Teacher();
    public Student(String name, int age, Double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

/*    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }*/
 @Override
    protected Object clone() throws CloneNotSupportedException {
        Student tem = (Student)super.clone();
        tem.teacher = (Teacher) this.teacher.clone();
        return tem;
    }
}
